package com.clovsoft.banner;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;

public class CircleView extends View {

    private Paint paint;
    private int radius = 20; // 圆的半径

    public CircleView(Context context) {
        super(context);
        init();
    }

    public CircleView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public CircleView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    private void init() {
        paint = new Paint();
        paint.setColor(Color.RED); // 圆的颜色
        paint.setAntiAlias(true); // 消除锯齿
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        // 计算圆心
        float centerX = getWidth() / 2;
        float centerY = getHeight() / 2;
        // 绘制圆形
        canvas.drawCircle(centerX, centerY, radius, paint);
    }

    // 设置圆的半径，可以动态修改
    public void setRadius(int radius) {
        this.radius = radius;
        invalidate(); // 重新绘制视图
    }

    @Override
    public void setBackground(Drawable background) {
        super.setBackground(background);

    }
}